package com.xuhai.blog19.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuhai.blog19.admin.dao.BannerDao;
import com.xuhai.blog19.admin.entity.BannerEntity;
import com.xuhai.blog19.admin.service.BannerService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author PangJunjie
 * @Date 2023/2/8/008
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerDao, BannerEntity> implements BannerService {
    @Override
    public IPage<BannerEntity> getPage(int page, int limit, BannerEntity banner) {
        return this.page(new Page<>(page, limit),
                new QueryWrapper<BannerEntity>()
                        .eq("type", banner.getType())
                        .eq(banner.getStatus() != null, "status", banner.getStatus())
                        .eq(StringUtils.isNotBlank(banner.getBannerName()), "banner_name", banner.getBannerName())
                        .orderByDesc("banner_id")
        );
    }

    @Override
    public List<BannerEntity> getListByType(int type) {
        return this.list(new QueryWrapper<BannerEntity>().eq("type", type).eq("status", 1));
    }
}
